﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL_Class;

namespace NLLSite.Administrator.UserControl
{
    public partial class Config : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack){
                fillConfig();
            }
        }
        

        protected void Button1_Click(object sender, EventArgs e)
        {
            ChinhSua cs = new ChinhSua();
            MyConfig cf = new MyConfig();

            cf.ID = 1;
            cf.IconUrl = txtFile.Text;
            cf.ButtonShare = CKEditorShareIcon.Text;
            cf.Title = txtTitle.Text;
            cf.Footer = ckeditorFooter.Text;
            cf.MetaTitle = txtMetaTitle.Text;
            cf.MetaDescription = txtMetaDescription.Text;
            cf.MetaKeywords = txtKeywords.Text;
            cf.MetaRobots = txtMetaRobots.Text;
            cf.MetaAuthor = txtMetaAuthor.Text;
            


            Label1.Text = cs.ConfigSite(cf);
            fillConfig();
        }
        public void fillConfig() {
            CKFinder.FileBrowser _FileBrowser = new CKFinder.FileBrowser();
            _FileBrowser.BasePath = "../../ckfinder/";
            _FileBrowser.SetupCKEditor(ckeditorFooter);

            CKFinder.FileBrowser _FileBrowserShare = new CKFinder.FileBrowser();
            _FileBrowserShare.BasePath = "../../ckfinder/";
            _FileBrowserShare.SetupCKEditor(CKEditorShareIcon);
            ChinhSua mcs = new ChinhSua();

            IEnumerable<DAL_Class.MyConfig> cfig = mcs.getConfig();
            foreach (DAL_Class.MyConfig mc in cfig)
            {
                txtFile.Text = mc.IconUrl;
                CKEditorShareIcon.Text = mc.ButtonShare;
                txtTitle.Text = mc.Title;
                ckeditorFooter.Text = mc.Footer;
                txtMetaTitle.Text = mc.MetaTitle;
                txtMetaDescription.Text = mc.MetaDescription;
                txtKeywords.Text = mc.MetaKeywords;
                txtMetaRobots.Text = mc.MetaRobots;
                txtMetaAuthor.Text = mc.MetaAuthor;
            }
        }
    }
}